<?php

declare(strict_types=1);

namespace App\Chat\Controller;

use App\Chat\Annotation\ChatAuth;
use App\Chat\Constant\FollowUpStatusConstant;
use App\Chat\Request\FollowUpRecordRequest;
use App\Chat\Request\TalkUrlRequest;
use App\Chat\Service\TalkFollowUpRecordService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;

#[Controller(prefix: 'ch/chat/followuprecord'),ChatAuth]
class TalkFollowUpRecordController extends ChatBaseController
{
    #[Inject]
    protected TalkFollowUpRecordService $service;


    #[PostMapping('list')]
    public function list(): \Psr\Http\Message\ResponseInterface
    {
        $data = $this->request->all();
        return $this->success($this->service->getRecords($data));
    }

    /**
     * @param FollowUpRecordRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('save')]
    public function save(FollowUpRecordRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->save($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 获取跟进状态列表
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('getStatusList')]
    public function getStatusList(): \Psr\Http\Message\ResponseInterface
    {
        return $this->success(FollowUpStatusConstant::getOptions());
    }

    /**
     * 删除链接
     * @param FollowUpRecordRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('delete')]
    public function delete(FollowUpRecordRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->delete([$request->input('id')]) ? $this->success() : $this->error();
    }
}